package com.itheima.homework.homework10;


import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class Test07 {
    /*
        现获取到一段文本，如下：
            wo ai heima wo ai java wo yao hao hao xue xi java
        单词间以空格分隔，请编写程序统计这段文本中每个单词出现的次数。
        输出格式如下：
            xi(1)java(2)yao(1)hao(2)wo(3)ai(2)heima(1)xue(1)
     */
    public static void main(String[] args) {
        String s = "wo ai heima wo ai java wo yao hao hao xue xi java";
        HashMap<String,Integer> hs = new HashMap<>();
        String[] split = s.split(" ");
        Set<String> set = hs.keySet();
        for (int i = 0; i < split.length; i++) {
            if (set.contains(split[i])){
                Integer integer = hs.get(split[i]);
                integer++;
                hs.put(split[i],integer);
            }else{
                hs.put(split[i], 1);
            }
        }
        Iterator<String> iterator = hs.keySet().iterator();
        while (iterator.hasNext()){
            String word = iterator.next();
            System.out.print(word+"("+hs.get(word)+")");
        }
    }
}
